const { executeSql, sqlEscape } = require('../utils/mysql')

module.exports = {
  userLoginDB: async (user) => {
    const { username, password } = sqlEscape(user)
    const sql = `select id, username, state from users where state >= 1 
      and username = ${username} and password = ${password};`
    return await executeSql(sql)
  },
  userRegisterDB: async (user) => {
    const { username, password, state } = sqlEscape(user)
    const sql = `insert into users (username, password, state) 
        values (${username}, ${password}, ${state});`
    return await executeSql(sql)
  },
  usernameCheckDB: async (username) => {
    const sql = `select id, state from users where username = ${sqlEscape(username)} and state >= 1;`
    return await executeSql(sql)
  }
}